//
//  LJPopularQACell.m
//  BaseProject
//
//  Created by 王洋 on 2020/12/11.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "LJPopularQACell.h"

@interface LJPopularQACell()<UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>


@end

@implementation LJPopularQACell

+ (CGFloat)calculateHeight {
    return 140;
}

- (void)awakeFromNib {
    [super awakeFromNib];


    [self initView];
}

- (void)fillWith:(NSMutableArray <CommunitySellerModel*>*)dataArray {
    self.dataArray = @[].mutableCopy;
    self.dataArray = dataArray;
    
    [self.collectionview reloadData];
}

- (void)initView {
    
    UICollectionViewFlowLayout *flowLaout = [[UICollectionViewFlowLayout alloc]init];
    flowLaout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    flowLaout.minimumInteritemSpacing = 5;
    flowLaout.minimumLineSpacing = 5;
    
    flowLaout.itemSize = CGSizeMake(290, 130);

    self.collectionview.collectionViewLayout = flowLaout;
    self.collectionview.delegate = self;
    self.collectionview.dataSource = self;
    self.collectionview.showsHorizontalScrollIndicator = NO;
    self.collectionview.showsVerticalScrollIndicator = NO;
    
    [self.collectionview registerNib:[UINib nibWithNibName:@"LJHotQACell" bundle:nil] forCellWithReuseIdentifier:@"LJHotQACellID"];

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    LJHotQACell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"LJHotQACellID" forIndexPath:indexPath];
    [cell fillWith:self.dataArray[indexPath.row]];
    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    if (self.LJPopularQACellBlock) {
        self.LJPopularQACellBlock(indexPath.row);
    }
}
@end
